<template>
	<view class="" style="padding: 0 30rpx;">
		<uni-forms ref="form" :rules="rules" :modelValue="formData">
			<uni-forms-item label="旧密码" name="oldPassword" required>
				<uni-easyinput type="password" v-model="formData.oldPassword" placeholder="输入旧密码" />
			</uni-forms-item>
			<uni-forms-item label="新密码" name="newPassword" required>
				<uni-easyinput type="password" v-model="formData.newPassword" placeholder="输入新密码" />
			</uni-forms-item>
			<uni-forms-item label="再次输入新密码" name="newPwd2" required>
				<uni-easyinput type="password" v-model="formData.newPwd2" placeholder="再次输入新密码" />
			</uni-forms-item>
		</uni-forms>
		<button type="primary" @click="amend">修改</button>
	</view>
</template>

<script>
	import rules from './validate.js'
	export default {
		data(){
			 return {
				 rules,
				 formData:{
					 oldPassword:'',
					 newPassword:'',
					 newPwd2:''
				 }
			 }
		},
		methods:{
			amend(){
				this.$refs.form.validate().then(params=>{
					console.log('表单数据信息：', params);
					uniCloud.callFunction({
						name:'uni-id-cf',
						data:{
							action:'amendPws',
							params
						},
						success: ({result}) => {
							console.log(result)
							if(result.code==0){
								uni.navigateTo({
									url:'/pages/login/login'
								})
							}else{
								uni.showToast({
									title:result.msg,
									icon:'none'
								})
							}
						}
					})
				}).catch(err =>{
					console.log('表单错误信息：', err);
				})
			}
		},
		onReady() {
			// 需要在onReady中设置规则
			this.$refs.form.setRules(this.rules)
		 },
	}
</script>

<style>
</style>
